import axios from "axios"
export default {
    namespaced:true,
    state: {
        adminData:[],
        array:[],
        searchType:'',
        searchValue:'',
        currentPage:1,
        pageSize:3,
        allPages:''//总页数
    },
    mutations: {
        getAdminData(state,payload){
            const a = payload.adminData.filter(item => item.admin_del ==0)//筛选未被删除的数据
            state.adminData = a;
            state.allPages = payload.pages - 0;
        },
        searchData(state,payload){
            state.searchType = payload.type;
            state.searchValue = payload.value;
        },
        changeCurrenPage(state,payload){
            state.currentPage = payload
        }
    },
    actions: {
        getAdminDataAsync(context){
            const {
                searchType,
                searchValue,
                currentPage,
                pageSize
            } = context.state;
            axios
            .get('/admin/get',{params:{searchType,searchValue,currentPage,pageSize}})
            .then(res =>{
                context.commit('getAdminData',res.data)//传给mutation的payload
            });
        }
    }
}